/*
 *    Copyright (c) 2018-2025, 云集汇通 All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the yunjihuitong.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 */

package com.yjht.modules.weixin.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yjht.common.constant.Constant;
import com.yjht.common.func.datafilter.DataFilter;
import com.yjht.common.utils.PageUtils;
import com.yjht.common.utils.ParamsUtils;
import com.yjht.common.utils.Query;
import com.yjht.modules.weixin.dao.WxcmsAccountDao;
import com.yjht.modules.weixin.entity.WxcmsAccountEntity;
import com.yjht.modules.weixin.service.WxcmsAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("wxcmsAccountService")
public class WxcmsAccountServiceImpl extends ServiceImpl<WxcmsAccountDao, WxcmsAccountEntity> implements WxcmsAccountService {
    @Autowired
    private WxcmsAccountDao wxcmsAccountDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<WxcmsAccountEntity> page = this.selectPage(
                new Query<WxcmsAccountEntity>(params).getPage(),
                new EntityWrapper<WxcmsAccountEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    @DataFilter(subDept = true, user = false)
    public PageUtils queryWxAccountPage(Map<String, Object> params, Query<WxcmsAccountEntity> query) {
        String keyword = (String) params.get("keyword");
        //keyword = "wjk";
        Page page = query.getPage();
        page.setCondition(params);
        EntityWrapper<WxcmsAccountEntity> ew = new EntityWrapper<>();
        WxcmsAccountEntity condition = new WxcmsAccountEntity();
        ew.setEntity(condition);
        ew.like("wx.name",keyword);
        params = ParamsUtils.getNewSqlFilter(params,"wx");
        ew.addFilterIfNeed(params.get(Constant.SQL_FILTER) != null, (String) params.get(Constant.SQL_FILTER));
        List<WxcmsAccountEntity> list = wxcmsAccountDao.queryWxAccountList(page,ew);
        page.setRecords(list);
        return new PageUtils(page);
    }

}
